import { http } from "@/utils/http";

// 接口响应类型定义
export interface AdminResponse {
  id: number;
  username: string;
  nickname: string;
  avatar: string;
  password: string;
  phone: string;
  status: number;
  role_id: number;
  role_name: string;
  create_time: number;
  update_time: number;
}

export interface LoginResponse {
  code: number;
  msg: string;
  data: {
    user: {
      id: number;
      username: string;
      nickname: string;
      avatar: string;
      role_id: number;
      permissions: Array<{
        id: number;
        path: string;
        name: string;
        parentId: number;
        meta: {
          title: string;
          icon: string;
          rank: number;
          auths: string[];
        };
        children: any[] | null;
      }>;
    }
  };
}

export interface PageResponse {
  total: number;
  page: number;
  pageSize: number;
  data: any[];
}

export interface Response {
  code: number;
  msg: string;
  data?: any;
}

// 管理员登录
export const adminLogin = (data: {
  username: string;
  password: string;
}) => {
  return http.request<LoginResponse>("post", "/investor/adminlogin", { data });
};

// 获取管理员列表
export const getAdminList = (data: {
  page: number;
  pageSize: number;
  keyword?: string;
  status?: number;
}) => {
  return http.request<Response>("post", "/investor/adminlist", { data });
};

// 获取管理员详情
export const getAdminInfo = (data: { id: number }) => {
  return http.request<Response>("post", "/investor/admininfo", { data });
};

// 创建管理员
export const createAdmin = (data: {
  username: string;
  password: string;
  nickname: string;
  phone?: string;
  status: number;
  role_id?: number;
}) => {
  return http.request<Response>("post", "/investor/adminadd", { data });
};

// 更新管理员
export const updateAdmin = (data: {
  id: number;
  username: string;
  nickname: string;
  phone: string;
  status: number;
  role_id: number;
  role_name?: string;
  avatar?: string;
}) => {
  return http.request<Response>("post", "/investor/adminupdate", { data });
};

// 删除管理员
export const deleteAdmin = (id: number) => {
  return http.request<Response>("post", `/investor/admindel`, { data: { id } });
};

// 修改管理员密码
export const updateAdminPassword = (data: {
  id: number;
  oldPassword: string;
  newPassword: string;
  confirmPassword: string;
}) => {
  return http.request<Response>("post", "/investor/adminupdatepwd", { data });
}; 